package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.SmsFlashPromotionProductRelationMapper;
import com.mall.dubbo.mapper.SmsFlashPromotionSessionMapper;
import com.mall.model.domain.SmsFlashPromotionProductRelation;
import com.mall.model.domain.SmsFlashPromotionSession;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【sms_flash_promotion_session(限时购场次表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class SmsFlashPromotionSessionApiImpl extends ServiceImpl<SmsFlashPromotionSessionMapper, SmsFlashPromotionSession>
        implements SmsFlashPromotionSessionApi {

    @Autowired
    private SmsFlashPromotionSessionMapper smsFlashPromotionSessionMapper;

    @Autowired
    private SmsFlashPromotionProductRelationMapper flashPromotionProductRelationMapper;


    //修改
    public void updateFlash(Integer id, SmsFlashPromotionSession smsFlashPromotion) {

        LambdaQueryWrapper<SmsFlashPromotionSession> lqw = new LambdaQueryWrapper<>();
        lqw.eq(id != null, SmsFlashPromotionSession::getId, Long.valueOf(id));

        smsFlashPromotionSessionMapper.update(smsFlashPromotion, lqw);
    }


    //统计商品数量
    public List<SmsFlashPromotionProductRelation> productCount(Integer flashPromotionId) {

        return flashPromotionProductRelationMapper.count(Long.valueOf(flashPromotionId));
    }

    @Override
    public List<SmsFlashPromotionSession> findByCreateTime(Date startDate, Date endDate) {

        LambdaQueryWrapper<SmsFlashPromotionSession> lqw = new LambdaQueryWrapper<>();
        lqw.between(SmsFlashPromotionSession::getCreateTime, startDate, endDate);

        return smsFlashPromotionSessionMapper.selectList(lqw);
    }


}




